/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dk.rofl.items;

import rofl.Utils;

/**
 *
 * @author Jeppe
 */
public class Armor extends Equipment {

    public static final int armorSlots = 5;
    public static final int SLOT_HEAD = 0;
    public static final int SLOT_CHEST = 1;
    public static final int SLOT_HANDS = 2;
    public static final int SLOT_LEGS = 3;
    public static final int SLOT_FEET = 4;
    private int slot;
    private int armorRating;

    public Armor(int slot, int armorRating, String name, int level, int quality) {
        super(GameItem.TYPE_ARMOR, name, level, quality);
        this.slot = slot;
        this.armorRating = armorRating;
    }

    public void setSlot(int slot) {
        this.slot = slot;
    }

    public int getSlot() {
        return slot;
    }

    public void setArmorRating(int armorRating) {
        this.armorRating = armorRating;
    }

    public int getArmorRating() {
        return armorRating;
    }

    public static Armor generateArmor(int itemLevel) {
        Armor a = generateArmor(itemLevel, Utils.rnd().nextInt(5), Equipment.generateItemQuality());
        return a;
    }

    public static Armor generateArmor(int itemLevel, int itemQuality) {
        Armor a = generateArmor(itemLevel, Utils.rnd().nextInt(5), itemQuality);
        return a;
    }

    public static Armor generateArmor(int itemLevel, int armorSlot, int itemQuality) {
        if (itemLevel < 1) {
            itemLevel = 1;
        }
        // Generate
        double aRating = (double) itemLevel * (2.0 + (double) Utils.rnd().nextInt(2));

        int half = itemLevel / 2 + 1;
        double bonus = (double) itemLevel - ((double) Utils.rnd().nextInt(itemLevel + 1) + half);
        double staBonus = itemLevel + bonus;
        double strBonus = itemLevel + (itemLevel - bonus);

        // Customize for each piece
        switch (armorSlot) {
            case Armor.SLOT_CHEST:
                aRating = aRating * 1.3;
                staBonus = staBonus * 1.3;
                strBonus = staBonus * 1.3;
                break;
            case Armor.SLOT_FEET:
                aRating = aRating * 1.0;
                staBonus = staBonus * 1.0;
                strBonus = staBonus * 1.0;
                break;
            case Armor.SLOT_HANDS:
                aRating = aRating * 1.0;
                staBonus = staBonus * 1.0;
                strBonus = staBonus * 1.0;
                break;
            case Armor.SLOT_HEAD:
                aRating = aRating * 1.2;
                staBonus = staBonus * 1.0;
                strBonus = staBonus * 1.0;
                break;
            case Armor.SLOT_LEGS:
                aRating = aRating * 1.3;
                staBonus = staBonus * 1.0;
                strBonus = staBonus * 1.0;
                break;
        }

        switch (itemQuality) {
            case Equipment.QUALITY_CRUDE:
                aRating = aRating * 0.9;
                staBonus = 0.0;
                strBonus = 0.0;
                break;
            case Equipment.QUALITY_NORMAL:
                aRating = aRating * 1.2;
                staBonus = 0.0;
                strBonus = 0.0;
                break;
            case Equipment.QUALITY_MAGIC:
                aRating = aRating * 1.3;
                if (staBonus < 1.0) {
                    staBonus = 1.0;
                }
                if (strBonus < 1.0) {
                    strBonus = 1.0;
                }
                break;
            case Equipment.QUALITY_SUPERIOR:
                aRating = aRating * 1.4;
                staBonus = staBonus * 2.0;
                strBonus = strBonus * 2.0;
                if (staBonus < 1.0) {
                    staBonus = 1.0;
                }
                if (strBonus < 1.0) {
                    strBonus = 1.0;
                }
                break;
            case Equipment.QUALITY_EPIC:
                aRating = aRating * 1.5;
                staBonus = staBonus * 3.0;
                strBonus = strBonus * 3.0;
                if (staBonus < 1.0) {
                    staBonus = 1.0;
                }
                if (strBonus < 1.0) {
                    strBonus = 1.0;
                }
                break;
        }

        // Create
        String aName = generatePrefix(itemQuality) + generateName(armorSlot) + generatePostfix(itemQuality);
        Armor a = new Armor(armorSlot, (int) aRating, aName, itemLevel, itemQuality);
        a.setStaminaBonus((int) staBonus);
        a.setStrengthBonus((int) strBonus);
        return a;
    }

    public static String generateName(int aSlot) {
        String s = "";

        switch (aSlot) {
            case Armor.SLOT_CHEST:
                s = "Chestpiece";
                break;
            case Armor.SLOT_FEET:
                s = "Boots";
                break;
            case Armor.SLOT_HANDS:
                s = "Gloves";
                break;
            case Armor.SLOT_HEAD:
                s = "Helmet";
                break;
            case Armor.SLOT_LEGS:
                s = "Pants";
                break;
        }
        return s;
    }
}
